package com.systemic.controller;

import com.systemic.core.ResponseResult;
import com.systemic.pojo.Admin;
import com.systemic.service.AdminService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @ClassName: AdminController
 * @Description:
 * @Author:
 * @CreateTime: 2024-02-04 08:05
 * @Version:
 **/
@RestController
@RequestMapping("/admin")
public class AdminController {

    @Resource
    private AdminService service;

    /**
     * 判断用户是否登录
     * @param account
     * @param password
     * @param session
     * @return
     */
    @PostMapping("/login/status")
    public ResponseResult<String> loginStatus(@RequestParam("account") String account,
                                              @RequestParam("password") String password,
                                              HttpSession session){
        Admin admin = new Admin();
        admin.setAccount(account);
        admin.setPassword(password);
        int row = service.verifyPassword(admin);
        if (row!=0){
            // 以账号作为Key值，Admin实体作为Values值
            session.setAttribute(account,admin);
            return ResponseResult.success("登录成功");
        }else {
            return ResponseResult.failed("账号或密码错误");
        }
    }



}
